package com.bookmarks;

import java.util.ArrayList;

import com.google.android.maps.GeoPoint;
import com.route.DetailedLocation;

public class BookmarksAdapter {
	public static boolean saveBookmarkList(ArrayList<DetailedLocation> locationList){
		String strBuilder = "";
		for(DetailedLocation dl:locationList){
			strBuilder += dl.getLocationName();
			strBuilder += ";";
			strBuilder += dl.getGeoPoint().getLatitudeE6();
			strBuilder += ";";
			strBuilder += dl.getGeoPoint().getLongitudeE6();
			strBuilder += ";";
			strBuilder += dl.getDescription();
			strBuilder += "\n";
		}
		BookmarksProvider.writeFile(strBuilder);
		return true;
	}
	public static ArrayList<DetailedLocation> retriveBookmarkList(){
		try{
			ArrayList<DetailedLocation> locationList = new ArrayList<DetailedLocation>();
			String rawString = BookmarksProvider.readFile();
			String [] rawBookmarks = rawString.split("\n");
			for(String rawBookmark:rawBookmarks){
				String [] rawDetailedLocation = rawBookmark.split(";");
				try{
					locationList.add(new DetailedLocation(rawDetailedLocation[0],new GeoPoint(Integer.parseInt(rawDetailedLocation[1]),Integer.parseInt(rawDetailedLocation[2])),rawDetailedLocation[3]));
				}catch(Exception e){
				}
			}
			return locationList;
		}catch(Exception e){
			return null;
		}


	}
}
